import { StorageKey } from "@/enums/dictionaries";
import { toArray } from "wsp-toolkit";
interface RoleVo {
  roleId: string;
  menuStr: string;
  roleName: string;
  status: "0" | "1";
}
interface UserInfo {
  nickName: string;
  userId: string;
  roleVOS: RoleVo[];
}
export function getUserInfo(): UserInfo {
  const userInfo = JSON.parse(
    localStorage.getItem(StorageKey.userInfo) || "{}",
  );
  return userInfo;
}

export function getAuthMenu() {
  const { roleVOS } = getUserInfo();
  return toArray(roleVOS).flatMap((role: any) => {
    if (role.status === "1") return [];
    return role.menuStr.split(",");
  });
}

export function isAdmin() {
  return getUserInfo().userId === "1";
}
